package com.example.modulemine.view.activity;



import android.content.res.AssetManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.example.baselibs.base.activity.BaseToolBarActivity;
import com.example.baselibs.router.path.ModuleMinePath;
import com.example.modulemine.R;
import com.example.modulemine.R2;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import butterknife.BindView;

@Route(path = ModuleMinePath.PATH_AGREE_PROTOCOL)
public class AgreeProtocolActivity extends BaseToolBarActivity {
    @BindView(R2.id.tv_agreement_content)
    TextView agreementContent;

    @Override
    public String setTitle() {
        return "客户端使用协议";
    }

    @Override
    public int getLayoutRes() {
        return R.layout.activity_agree_protocol;
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        agreementContent.setMovementMethod(ScrollingMovementMethod.getInstance());
        new ReadTextTask().execute();
    }

    private class ReadTextTask extends AsyncTask<Void,Void,String> {
        @Override
        protected String doInBackground(Void... voids) {
            AssetManager manager=getResources().getAssets();

            try {
                InputStream is=manager.open("agreement.txt");
                InputStreamReader isr=new InputStreamReader(is,"UTF-8");
                BufferedReader br=new BufferedReader(isr);
                StringBuffer sb=new StringBuffer();
                String length;
                while ((length=br.readLine())!=null){
                    sb.append(length+"\n");
                }
                br.close();
                isr.close();
                is.close();
                return sb.toString();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return "文件读取失败";
        }

        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
            agreementContent.setText(s);
        }
    }
}
